package com.crc.luojian.component;

import com.crc.luojian.annotation.Autowired;
import com.crc.luojian.annotation.Component;
import com.crc.luojian.util.ConnectionUtils;
import lombok.EqualsAndHashCode;
import org.apache.catalina.Session;
import org.apache.commons.dbutils.DbUtils;

import java.sql.Connection;
import java.sql.SQLException;

/**
 * @program: luojian-springframework
 * @description:
 * @author: luojian58
 * @create: 2021-06-14 11:09
 */

public class TransactionManager {

    // 开启手动事务控制
    public void beginTransaction() throws SQLException {
        Connection connection  = ConnectionUtils.getCurrentThread();
        connection.setAutoCommit(false);
    }

    // 提交事务
    public  void commit() throws SQLException {
        Connection connection  = ConnectionUtils.getCurrentThread();
        connection.commit();

    }

    // 回滚事务
    public  void rollback() throws SQLException {
        Connection connection  = ConnectionUtils.getCurrentThread();
        connection.rollback();
    }

    public  void setAutoCommit(boolean b) throws SQLException {
        Connection connection  = ConnectionUtils.getCurrentThread();
        connection.setAutoCommit(true);
    }

    public void releaseConnection() {
        ConnectionUtils.releaseConnection();
    }
}
